package com.hero.updown;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.lzy.okgo.OkGo;

public class ProgressBarDialog extends Dialog {


    private ProgressBar firstProgressBar;
    private TextView tv_updown_path_title;
    private TextView tv_updown_path;
    private TextView tv_save_path;
    private Button bt_close;

    private int mType = 0; //0：上传 1：下载
    private StatusCallback callback;

    public ProgressBarDialog(@NonNull Context context,StatusCallback callback,int type) {
        super(context);
        this.mType = type;
        this.callback = callback;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_pb);
        bt_close = findViewById(R.id.bt_close);
        tv_updown_path_title = findViewById(R.id.tv_updown_path_title);
        tv_updown_path = findViewById(R.id.tv_updown_path);
        tv_save_path = findViewById(R.id.tv_save_path);
        firstProgressBar = findViewById(R.id.firstProgressBar);
        setCanceledOnTouchOutside(false);
        setCancelable(false);

        tv_updown_path_title.setText(mType == 0?"上传地址：":"下载地址：");
        bt_close.setText(mType == 0?"取消上传":"取消下载");
        firstProgressBar.setMax(10000);

        findViewById(R.id.bt_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                OkGo.getInstance().cancelAll();
                dismiss();
                if (callback != null){
                    callback.ok();
                }
            }
        });

    }

    public void setProgress(float fraction){
        firstProgressBar.setProgress((int) (fraction * 10000));
    }
    public void setText1(String url){
        tv_updown_path.setText(url);
    }
    public void setText2(String url){
        tv_save_path.setText(url);
    }

    public void setClose(){
        bt_close.setText("关闭");
    }

}
